/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;


public abstract class JPanelSearch extends javax.swing.JPanel {

    private static final long serialVersionUID = 1L;
    protected String initialSearchBoxValue;
    protected String initialSearchFormHeaderText;

    void search() {
        jPanelContents.removeAll();
        GUIUtils.setImageAtSize(jLabelSearchLoading, 24, 24, "/resources/waiting.gif");
        jLabelSearchLoading.setVisible(true);
        jPanelContents.requestFocus();
    }

    abstract void setComponentsInitialTextValues();

    /**
     * Creates new form JPanelBooksSearch
     */
    public JPanelSearch() {
        setComponentsInitialTextValues();
        initComponents();
        initAuxComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this
     * code. The content of this method is always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelHeader = new javax.swing.JLabel();
        jPanelSearch = new javax.swing.JPanel();
        jPanelSearchFirstLine = new javax.swing.JPanel();
        jTextFieldSearch = new javax.swing.JTextField();
        jLabelSearchButton = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanelContents = new javax.swing.JPanel();

        setBackground(new java.awt.Color(51, 153, 255));
        setAutoscrolls(true);

        jLabelHeader.setBackground(new java.awt.Color(51, 153, 255));
        jLabelHeader.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
        jLabelHeader.setForeground(new java.awt.Color(153, 255, 153));
        jLabelHeader.setText(initialSearchFormHeaderText);

        jPanelSearch.setOpaque(false);
        jPanelSearch.setLayout(new javax.swing.BoxLayout(jPanelSearch, javax.swing.BoxLayout.PAGE_AXIS));

        jPanelSearchFirstLine.setOpaque(false);

        jTextFieldSearch.setText(initialSearchBoxValue);
        jTextFieldSearch.addActionListener(new java.awt.event.ActionListener() {
            @Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldSearchActionPerformed(evt);
            }
        });
        jTextFieldSearch.addFocusListener(new java.awt.event.FocusAdapter() {
            @Override
			public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldSearchFocusGained(evt);
            }
            @Override
			public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldSearchFocusLost(evt);
            }
        });

        jLabelSearchButton.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
			public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelSearchButtonMouseClicked(evt);
            }
        });

        jLabelSearchLoading.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
			public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelSearchLoadingMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelSearchFirstLineLayout = new javax.swing.GroupLayout(jPanelSearchFirstLine);
        jPanelSearchFirstLine.setLayout(jPanelSearchFirstLineLayout);
        jPanelSearchFirstLineLayout.setHorizontalGroup(
            jPanelSearchFirstLineLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSearchFirstLineLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextFieldSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 519, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jLabelSearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jLabelSearchLoading, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );
        jPanelSearchFirstLineLayout.setVerticalGroup(
            jPanelSearchFirstLineLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSearchFirstLineLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextFieldSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jLabelSearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jLabelSearchLoading, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jPanelSearch.add(jPanelSearchFirstLine);

        jScrollPane2.setBackground(new java.awt.Color(51, 153, 255));
        jScrollPane2.setBorder(null);
        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setOpaque(false);

        jPanelContents.setBackground(new java.awt.Color(51, 153, 255));
        jPanelContents.setAlignmentY(0.0F);
        jPanelContents.setAutoscrolls(true);
        jPanelContents.setLayout(new javax.swing.BoxLayout(jPanelContents, javax.swing.BoxLayout.Y_AXIS));
        jScrollPane2.setViewportView(jPanelContents);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabelHeader, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jPanelSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(10, 10, 10))
            .addComponent(jScrollPane2)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelHeader)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldSearchActionPerformed
        search();
    }//GEN-LAST:event_jTextFieldSearchActionPerformed

    private void jTextFieldSearchFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldSearchFocusGained
        GUIUtils.handleJTextFieldFocusGained(jTextFieldSearch, initialSearchBoxValue);
    }//GEN-LAST:event_jTextFieldSearchFocusGained

    private void jTextFieldSearchFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldSearchFocusLost
        GUIUtils.handleJTextFieldFocusLost(jTextFieldSearch, initialSearchBoxValue);
    }//GEN-LAST:event_jTextFieldSearchFocusLost

    private void jLabelSearchButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelSearchButtonMouseClicked
        search();
    }//GEN-LAST:event_jLabelSearchButtonMouseClicked

    private void jLabelSearchLoadingMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelSearchLoadingMouseClicked
        
    }//GEN-LAST:event_jLabelSearchLoadingMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JLabel jLabelHeader;
    private javax.swing.JLabel jLabelSearchButton;
    protected static final javax.swing.JLabel jLabelSearchLoading = new javax.swing.JLabel();
    protected javax.swing.JPanel jPanelContents;
    protected javax.swing.JPanel jPanelSearch;
    private javax.swing.JPanel jPanelSearchFirstLine;
    private javax.swing.JScrollPane jScrollPane2;
    protected javax.swing.JTextField jTextFieldSearch;
    // End of variables declaration//GEN-END:variables

    protected void initAuxComponents() {
        GUIUtils.setImageAtSize(jLabelSearchButton, 24, 24, "/resources/search.png");
        GUIUtils.setURLLink(jLabelSearchButton, null, false);
    }

}
